
/* 
当打包构建应用时，JavaScript 包会变得非常大，影响页面加载。
如果我们能把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就会更加高效。
*/
export default [
    {
        path:"/home",
        component:() => import('@/pages/Home'),
        meta:{
            show:true
        }
    },
    {
        name:'search',
        path:"/search/:keyword?",
        component:() => import('@/pages/Search'),
        meta:{
            show:true
        },
    },
    {
        name:'login',
        path:"/login",
        component:() => import('@/pages/Login')
    },
    {
        path:"/register",
        component:() => import('@/pages/Register')
    },
    {
        path:"/detail/:skuid",
        component:() => import('@/pages/Detail'),
        meta:{
            show:true
        }
    },
    {
        name:'shopcart',
        path:"/shopcart",
        component:() => import('@/pages/ShopCart'),
        meta:{
            show:true
        }
    },
    {
        name:'addcartsuccess',
        path:"/addcartsuccess",
        component:() => import('@/pages/AddCartSuccess'),
        meta:{
            show:true
        } 
    },
    {
        name:'trade',
        path:"/trade",
        component:() => import('@/pages/Trade'),
        meta:{
            show:true
        },
        beforeEnter: (to, from, next) => {
            if(from.path == '/shopcart'){
                next();
            }else{
                next(false);
            }
        }
    },
    {
        name:'pay',
        path:"/pay",
        component:() => import('@/pages/Pay'),
        meta:{
            show:true
        },
        beforeEnter: (to, from, next) => {
            if(from.path == '/trade'){
                next();
            }else{
                next(false);
            }
        }
    },
    {
        name:'paysuccess',
        path:"/paysuccess",
        component:() => import('@/pages/PaySuccess'),
        meta:{
            show:true
        }
    },
    {
        name:'center',
        path:"/center",
        component:() => import('@/pages/Center'),
        meta:{
            show:true
        },
        children:[
            {
                path:'myorder',
                component:() => import('@/pages/Center/MyOrder')
            },
            {
                path:'grouporder',
                component:() => import('@/pages/Center/GroupOrder')
            },
            {
                path:'/center',
                redirect:'/center/myorder'
            },
        ]
    },
    
    //重定向
    {
        path:'*',
        redirect:'/home'
    }
]